package com.cy.controller;


import com.cy.common.ResultResponse;
import com.cy.config.RequiresRole;
import com.cy.entity.Courses;
import com.cy.entity.Documents;
import com.cy.entity.Users;
import com.cy.service.IDocumentsService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  文档管理控制层
 * </p>
 *
 * @author Aleven
 * @since 2024-12-21
 */
@RestController
@RequestMapping("/documents")
public class DocumentsController {

    @Autowired
    IDocumentsService iDocumentsService ;


    //查询所有文档
    @Operation(summary = "查询所有文档")
    @GetMapping("/FindAllDocuments")
    public List<Documents> FindAllDocuments(){

        List<Documents> documentsAll = iDocumentsService.FindAllDocuments();
        return documentsAll;
    }


    //根据条件查询文档
    @Operation(summary = "根据条件查询文档")
    @GetMapping("/FindByCondition")
    public ResultResponse FindByCondition(Documents documents){

        List<Documents> documwentsCondition = iDocumentsService.FindByCondition(documents);
        return ResultResponse.success(documwentsCondition,documwentsCondition.size());
    }


    //增加文档
    @Operation(summary = "文档增加")
    @PostMapping("/insertDocuments")
    @RequiresRole("2")//仅管理员
    ResultResponse insertDocuments(@RequestBody Documents documents) throws Exception{
        return iDocumentsService.insertDocuments(documents) ;

    }


    //修改文档
    @Operation(summary = "文档修改")
    @PutMapping("/updateDocuments")
    @RequiresRole("2")//仅管理员
    ResultResponse updateDocuments(@RequestBody Documents documents) throws Exception{
        return iDocumentsService.updateDocuments(documents) ;
    }


    //删除文档
    @Operation(summary = "删除文档信息")
    @DeleteMapping("/delDocuments")
    @RequiresRole("2")//仅管理员
    public ResultResponse delDocuments(String DocumentID){
        int i = iDocumentsService.delDocuments(DocumentID);

        return i>0?ResultResponse.success():ResultResponse.fail();
    }






}
